home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.5 KB | 411 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Dialog.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWDIALOG_H
- #include "FWDialog.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFLOWIN_H
- #include "FWFloWin.h"
- #endif
-
- #ifndef FWTABBER_H
- #include "FWTabber.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWIDLE_H
- #include "FWIdle.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- FW_DEFINE_CLASS_M2(FW_CDialogFrame, FW_CFrame, FW_MReceiver)
- FW_DEFINE_AUTO(FW_CDialogFrame)
-
- //========================================================================================
- // class FW_CDialogFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::FW_CDialogFrame
- //----------------------------------------------------------------------------------------
- FW_CDialogFrame::FW_CDialogFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_CPart* part)
- : FW_CFrame(ev, odFrame, presentation, part),
- FW_MReceiver(),
- fDefaultButton(NULL),
- fCancelButton(NULL)
- {
- // Add a ViewTabber and an idler by default
- fViewTabber = new FW_CViewTabber(ev, this);
-
- fIdler = FW_NEW(FW_CIdler, (this, 15));
- fIdler->RegisterIdle(ev);
-
- fIsModal = TRUE; // [LSD] see non-modal dialogs later
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::~FW_CDialogFrame
- //----------------------------------------------------------------------------------------
-
- FW_CDialogFrame::~FW_CDialogFrame()
- {
- FW_START_DESTRUCTOR
-
- delete fIdler;
- fIdler = NULL;
-
- // fViewTabber event handler is deleted automatically
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::PrivButtonAttached
- //----------------------------------------------------------------------------------------
-
- void FW_CDialogFrame::PrivButtonAttached(Environment* ev, FW_CButton* button)
- {
- if (button->GetMessage(ev) == FW_kDefaultButtonMsg)
- {
- fDefaultButton = PrivSetDismissButton(ev, button, FW_kDefaultButtonMsg, fDefaultButton);
- }
- else if (button->GetMessage(ev) == FW_kCancelButtonMsg)
- {
- fCancelButton = PrivSetDismissButton(ev, button, FW_kCancelButtonMsg, fCancelButton);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogHandler::SetDefaultButton
- //----------------------------------------------------------------------------------------
-
- void FW_CDialogFrame::SetDefaultButton(Environment* ev, ODID id)
- {
- // Use this method only if you want to change or remove an existing default button.
- // (Use id = 0 to remove an existing default button)
- // The dialog's default button is automatically set when you use FW_kDefaultButtonMsg
- // for the button's message value (either in code or resources)
-
- FW_CButton* button = NULL;
- if (id != 0)
- {
- button = FW_DYNAMIC_CAST(FW_CButton, FindViewByID(ev, id));
- FW_ASSERT(button);
- }
-
- fDefaultButton = PrivSetDismissButton(ev, button, FW_kDefaultButtonMsg, fDefaultButton);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::SetCancelButton
- //----------------------------------------------------------------------------------------
-
- void FW_CDialogFrame::SetCancelButton(Environment* ev, ODID id)
- {
- // Use this method only if you want to change or remove an existing cancel button.
- // (Use id = 0 to remove an existing cancel button)
- // The dialog's cancel button is automatically set when you use FW_kCancelButtonMsg
- // for the button's message value (either in code or resources)
-
- FW_CButton* button = NULL;
- if (id != 0)
- {
- button = FW_DYNAMIC_CAST(FW_CButton, FindViewByID(ev, id));
- FW_ASSERT(button);
- }
-
- fCancelButton = PrivSetDismissButton(ev, button, FW_kCancelButtonMsg, fCancelButton);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogHandler::PrivSetDismissButton
- //----------------------------------------------------------------------------------------
-
- FW_CButton* FW_CDialogFrame::PrivSetDismissButton(Environment* ev, FW_CButton* newButton, FW_Message message, FW_CButton* prevButton)
- {
- if (prevButton)
- {
- // Remove outline
- if (message == FW_kDefaultButtonMsg)
- prevButton->SetButtonKind(ev, FW_kPushButton);
-
- // Remove connection
- RemoveInterest(prevButton, message);
-
- // Reset button's message
- prevButton->SetMessage(ev, FW_kNullMsg);
-
- prevButton = NULL;
- }
-
- if (newButton) {
- // Add outline
- if (message == FW_kDefaultButtonMsg)
- newButton->SetButtonKind(ev, FW_kDefaultPushButton);
- // Set the button's message & connect dialog
- newButton->SetMessage(ev, message);
- newButton->LinkControlTo(ev, this);
- }
-
- return newButton;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void FW_CDialogFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- // ---- close the dialog on OK or Cancel ----
- if (notification.GetMessage() == FW_kDefaultButtonMsg ||
- notification.GetMessage() == FW_kCancelButtonMsg)
- {
- GetWindow(ev)->CloseAndRemove(ev);
- // ATTENTION: The whole window is gone at this point. So don't try to do
- // anything after this point
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::NewModalDialog
- //----------------------------------------------------------------------------------------
-
- FW_CDialogFrame* FW_CDialogFrame::NewModalDialog(Environment* ev,
- FW_CPart* part,
- FW_CPresentation* presentation,
- const FW_CPoint& size,
- const FW_CPoint& position,
- FW_WindowStyle style,
- const FW_CString& windowTitle)
- {
- // [LSD] todo: add checking on authorized window styles. See FWWindow.k
- FW_WindowStyle winStyle = FW_kModalDialog | style;
-
- // Create dialog window (which in turn will create a dialog frame through the
- // part's NewFrame method, will create a facet and will create the subviews)
- FW_CWindow* dialogWindow = new FW_CWindow(ev, part,
- NULL, // no parent frame
- FALSE, // Dialogs are not persistent
- FW_CPart::fgViewAsFrameToken,
- presentation,
- windowTitle,
- size,
- position,
- winStyle);
-
- // Use standard position
- if ((winStyle & FW_kStandardDialogPosition) != 0)
- {
- FW_PlatformError error;
- ::FW_PositionModalDialog(dialogWindow->GetPlatformWindow(ev), &error);
- FW_FailOnError(error);
- }
-
- // Get the dialog frame from the window and try to open it
- FW_CAcquiredODWindow aqODDialog = dialogWindow->AcquireODWindow(ev);
- ODFrame* odFrame = aqODDialog->GetRootFrame(ev);
- FW_CDialogFrame* dialogFrame = (FW_CDialogFrame *)FW_CFrame::ODtoFWFrame(ev, odFrame);
- FW_Boolean isMoveable = winStyle & FW_kHasCaption ? true : false;
-
- if (dialogFrame->TryModalFocus(ev, odFrame, isMoveable) == FALSE) {
- // modal focus could not be granted
- delete dialogWindow;
- return NULL;
- }
- return dialogFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::NewAndShowModalDialog
- //----------------------------------------------------------------------------------------
- // Same as NewModalDialog but show the window too. Useful when no initialization is needed
-
- FW_CDialogFrame* FW_CDialogFrame::NewAndShowModalDialog(Environment* ev,
- FW_CPart* part, FW_CPresentation* presentation,
- const FW_CPoint& size, const FW_CPoint& position,
- FW_WindowStyle style, const FW_CString& windowTitle)
- {
- FW_CDialogFrame* dialogFrame = NewModalDialog(ev, part, presentation, size, position,
- style, windowTitle);
-
- if (dialogFrame != NULL)
- {
- dialogFrame->GetWindow(ev)->Show(ev);
- }
- return dialogFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::TryModalFocus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDialogFrame::TryModalFocus(Environment* ev, ODFrame* odFrame, FW_Boolean isMoveable)
- {
- if (FW_CSession::GetArbitrator(ev)->RequestFocus(ev, FW_CPart::fgModalFocusToken, odFrame))
- {
- // Add modal focus to the frame's focus set
- GetFocusSet(ev)->Add(ev, FW_CPart::fgModalFocusToken);
-
- // Hide floating windows
- FW_CFloatingWindow::HideShowFloatingWindows(ev, FALSE);
-
- // Disable the whole menubar
- // (Edit menu will be enabled later if dialog contains an active text-edit)
- if (fIsModal)
- GetPart(ev)->PrivEnableMenuBar(ev, FALSE, isMoveable);
-
- // Select the first target
- fViewTabber->Tab(ev, this);
-
- return TRUE;
- }
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::FrameRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CDialogFrame::FrameRemoved(Environment* ev, FW_Boolean toStorage)
- {
- // ----- re-enable the menubar after Modal dialog
- if (fIsModal)
- GetPart(ev)->PrivEnableMenuBar(ev, true, false);
-
- // ----- Call inherited -----
- FW_CFrame::FrameRemoved(ev, toStorage);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDialogFrame::DoVirtualKey
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CDialogFrame::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent & event)
- {
- FW_Handled handled = FW_kNotHandled;
- FW_CButton* button = NULL;
-
- switch (event.GetKeyCode(ev)) {
- case FW_kVKEnter:
- case FW_kVKReturn:
- button = GetDefaultButton(ev);
- break;
-
- case FW_kVKEscape:
- button = GetCancelButton(ev);
- break;
-
- default:
- if (event.IsCommandPeriod(ev)) {
- button = GetCancelButton(ev);
- }
- break;
- }
-
- if (button) {
- button->SimulateButtonPressed(ev);
- handled = FW_kHandled;
- }
-
- // returning FW_kNotHandled will propagate the same key as a CharKeyEvent on the Mac
- return handled;
- }
-
-
-